/*****************************************************
Copyright (C) 2020. All rights reserved.
File name     ：TestMain.c
Version       ：v1.0
Author        ：zhengqijun
Date          ：2020-04-30
Function List ：
Description   ：main function
******************************************************/

#include <stdio.h>   // for printf
#include <time.h>    // for time
#include <stdlib.h>  // for rand & srand
#include "BucketSort.h"
#include "FatalError.h"

// PrintArray for testing
static void PrintArray(ElementType A[], int N);
static ElementType *GetRandomArray(ElementType Min, ElementType Max, int N);

void PrintArray(ElementType A[], int N) {
    int i = 0;

    printf("Print Array:[ ");
    for (i = 0; i < N; ++i) {
        printf("%d ", A[i]);
    }
    printf("]\n");
}

ElementType *GetRandomArray(ElementType Min, ElementType Max, int N) {
    ElementType *A;
    int i;

    A = (ElementType *)malloc(N * sizeof(ElementType));
    if (A == NULL) {
        FatalError("Out of space!!!");
    }

    srand(time(NULL));
    for (i = 0; i < N; ++i) {
        A[i] = rand() % (Max - Min + 1) + Min;
    }

    return A;
}

// main function
int main(void) {
    ElementType *arr;
    int Size = 40;

    arr = GetRandomArray(1, 999, Size);

    printf("Array before sort\n");
    PrintArray(arr, Size);

    BucketSort(arr, Size);

    printf("Array after sort\n");
    PrintArray(arr, Size);

    free(arr);

    return 0;
}

// EOF

